package com.dabaozhan.modules.wx_app.controller;

import com.alibaba.fastjson.JSON;
import com.dabaozhan.common.exception.RRException;
import com.dabaozhan.common.utils.OmsPage;
import com.dabaozhan.modules.wx_app.base.ResponseDto;
import com.dabaozhan.modules.wx_app.entity.QuotationtrendEntity;
import com.dabaozhan.modules.wx_app.enums.ResponseCodeEnum;
import com.dabaozhan.modules.wx_app.service.QuotationtrendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author houzhong
 * @date 2019-01-14 18:04
 */
@Api(value = "打包站行情咨询", description = "打包站行情咨询")
@RestController
@RequestMapping("/wx_app")
public class QuotationtrendController {

    private static final Logger LOGGER = LoggerFactory.getLogger(QuotationtrendController.class);

    /**行情查询*/
    @Autowired
    private QuotationtrendService quotationtrendService;

    @ApiOperation(value = "行情资讯查询")
    @RequestMapping(value = "/quotationtrendList")
    public  String quotationtrendList(QuotationtrendEntity v, Integer page, Integer size){
        ResponseDto<OmsPage<QuotationtrendEntity>> responseDto = new ResponseDto<OmsPage<QuotationtrendEntity>>();
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("page",(page - 1) * size);
            params.put("size",size);
            params.put("categoryId",v.getCategoryId());
            OmsPage<QuotationtrendEntity> pages = quotationtrendService.findByQuotationtrend(params);
            responseDto.setResponseCodeEnum(ResponseCodeEnum.ResponseCode_100);
            responseDto.setResult(pages);
        } catch(RRException re){
            responseDto.setCode(re.getCode());
            responseDto.setMessage(re.getMessage());
        } catch (Exception e) {
            responseDto.setResponseCodeEnum(ResponseCodeEnum.ResponseCode_500);
            //记录异常日志
            LOGGER.error("订单查询发生异常:",e);
        } finally {
            //记录请求入参和返回日志
            LOGGER.info("订单查询发生异常:{}-返回结果:{}", JSON.toJSONString(v),JSON.toJSONString(responseDto));
        }
        return JSON.toJSONString(responseDto);
    }

    /**
     * 详情
     * @param id
     * @return
     */
    @ApiOperation(value = "查询行情详情")
    @RequestMapping(value = "/toQuotationtrendDetails")
    public String toQuotationtrendDetails(String id) {
        ResponseDto<QuotationtrendEntity> responseDto = new ResponseDto<QuotationtrendEntity>();
        try {
            QuotationtrendEntity quotationtrend = quotationtrendService.getQuotationtrendId(id);
        } catch(RRException re){
            responseDto.setCode(re.getCode());
            responseDto.setMessage(re.getMessage());
        } catch (Exception e) {
            responseDto.setResponseCodeEnum(ResponseCodeEnum.ResponseCode_500);
            //记录异常日志
            LOGGER.error("查询行情详情发生异常:",e);
        } finally {
            //记录请求入参和返回日志
            LOGGER.info("查询行情详情发生异常:{}-返回结果:{}", JSON.toJSONString(responseDto));
        }

        return JSON.toJSONString(responseDto);
    }
}
